package cn.wjzhang.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.wjzhang.entity.NavSiteEntity;
import cn.wjzhang.mapper.NavSiteMapper;
import cn.wjzhang.service.NavSiteService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 导航网站
 *
 * @author wj
 * @date 2023-09-27 17:21:26
 */
@Service
public class NavSiteServiceImpl extends ServiceImpl<NavSiteMapper, NavSiteEntity> implements NavSiteService {

    @Override
    public Map<Long, List<NavSiteEntity>> queryByGroup() {
        List<NavSiteEntity> list = this.list(Wrappers.<NavSiteEntity>lambdaQuery().eq(NavSiteEntity::getDelFlag, "0"));
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, List<NavSiteEntity>> map = list.stream()
                    .sorted(Comparator.comparing(NavSiteEntity::getSort))
                    .collect(Collectors.groupingBy(NavSiteEntity::getCategoryId));
            return map;
        }
        return null;
    }
}